package upload;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.io.FileCleaningTracker;

import java.io.File;

/**
 * 
 * @author CSDN
 *
 */
public class MyDiskFileItemFactory extends DiskFileItemFactory {
	
    private OutputStreamListener listener = null;

    public MyDiskFileItemFactory(OutputStreamListener listener) {
        super();
        this.listener = listener;
    }

    public MyDiskFileItemFactory(int sizeThreshold, File repository, OutputStreamListener listener) {
        super(sizeThreshold, repository);
        this.listener = listener;
    }

    @Override
    public FileItem createItem(String fieldName, String contentType, boolean isFormField, String fileName) {
    	MyDiskFileItem result = new MyDiskFileItem(fieldName, contentType,
                isFormField, fileName, getSizeThreshold(), getRepository(), listener);
    	FileCleaningTracker tracker = getFileCleaningTracker();
        if (tracker != null) {
            tracker.track(result.getTempFile(), this);
        }
        return result;
    }
    
}
